<?php

/*
 * to change this template, choose tools | templates
 * and open the template in the editor.
 */

/**
 * description of webservice
 *
 * @author montecristo
 */
class webservice extends ci_controller{
    
    public function __construct() {
        parent::__construct();
        $this->load->model("webservice/webserice_model","modal");
        
    }
    
    
    public function getapp($key,$serie){
        if($key=="43b5dc92c7f385ed4977843832c00640"){
           echo json_encode($this->modal->getaplicaciones($serie));
        }else{
           echo "false"; 
        }
    }
    
    public function getcliente($key,$id){
       if($key=="43b5dc92c7f385ed4977843832c00640"){
        echo json_encode($this->modal->getcliente($id)); 
        }else{
           echo "false"; 
        }
    }
    
    public function getencuesta($key,$id){
        if($key=="43b5dc92c7f385ed4977843832c00640"){
         echo json_encode($this->modal->getencuesta($id));  
        }else{
           echo "false"; 
        }
    }
    
    
    public function getservicios($key,$serie){
        if($key=="43b5dc92c7f385ed4977843832c00640"){
         $array=$this->modal->getserviciosm($serie);
          if(count($array["servicios"])>0)  
            echo json_encode($array);
          else
            echo "0"; 
        }else{
           echo "0"; 
        }
    }
    
    
    public function insertrespuestas(){
        $key=$this->input->post("key");
        $josonstring=$this->input->post("respuestas");
        if($key=="43b5dc92c7f385ed4977843832c00640"){
        
          $this->modal->insertrespuestasm($josonstring);
          //  $array=json_decode( $josonstring,true); 
            echo "true";//count($array);
        }else{
           echo "false"; 
        }
        
    }
    
     public function changestatus(){
        
         
         
         try {
              $key=$this->input->post("key");
                $josonstring=$this->input->post("app");
                if($key=="43b5dc92c7f385ed4977843832c00640"){
        
          echo $this->modal->changestatusm($josonstring);
          
             
        }else{
           echo "false"; 
        }
             
         } catch (exception $exc) {
              echo "false"; 
         }



        
        
    }
    
    
    
    public function setposicion($key,$serie,$fecha,$lat,$lon,$codigo,$comentario){
     try {   
        if($key=="43b5dc92c7f385ed4977843832c00640"){        
            
           $this->modal->setposicionm($serie,$fecha,$lat,$lon,$codigo,$comentario);          
             
        }else{
           echo "0"; 
        }
             
         } catch (exception $exc) {
              echo "0"; 
         }
        
    }


    
    public function prueba($id){
        
               
       
        $this->modal->changestatusasincronizada($id);
        
    }
    public function geteventos($key,$serie){
        if($key=="43b5dc92c7f385ed4977843832c00640"){
         $array=$this->modal->geteventosm($serie);
          
            echo json_encode($array);
          
        }else{
           echo "0"; 
        }
    }
    
    
   public function getdireccion(){
        
        if(!empty($_get["lat"]) && !empty($_get["lon"])){

    $servicio="http://148.213.1.38:8085/service.asmx?wsdl"; 
  $parametros=array(); 
   
    $parametros['latitude']=$_get["lat"];
    $parametros['longitud']=$_get["lon"];
    $client = new soapclient($servicio, $parametros);
    $result = $client->getaddress($parametros);
    $jresult = $result->getaddressresult;
 
    echo($jresult);
    }else{

    echo "descpnocido";
  }
        
    }
    
}



?>
